package com.linxiao.call.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.linxiao.call.domain.CrmTelephoneConfig;
import com.linxiao.call.mapper.CrmTelephoneConfigMapper;
import com.linxiao.call.service.ICrmTelephoneConfigService;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户IP话机配置Service业务层处理
 * 
 * @author zhoudong
 * @date 2022-08-24
 */
@Service
public class CrmTelephoneConfigServiceImpl implements ICrmTelephoneConfigService
{
    @Autowired
    private CrmTelephoneConfigMapper crmTelephoneConfigMapper;

    /**
     * 查询用户IP话机配置
     * 
     * @param id 用户IP话机配置主键
     * @return 用户IP话机配置
     */
    @Override
    public CrmTelephoneConfig selectCrmTelephoneConfigById(Long id)
    {
        return crmTelephoneConfigMapper.selectCrmTelephoneConfigById(id);
    }

    /**
     * 查询用户IP话机配置列表
     * 
     * @param crmTelephoneConfig 用户IP话机配置
     * @return 用户IP话机配置
     */
    @DataScope(deptAlias = "s")
    @Override
    public List<CrmTelephoneConfig> selectCrmTelephoneConfigList(CrmTelephoneConfig crmTelephoneConfig)
    {
        return crmTelephoneConfigMapper.selectCrmTelephoneConfigList(crmTelephoneConfig);
    }

    /**
     * 新增用户IP话机配置
     * 
     * @param crmTelephoneConfig 用户IP话机配置
     * @return 结果
     */
    @Override
    public int insertCrmTelephoneConfig(CrmTelephoneConfig crmTelephoneConfig)
    {
        crmTelephoneConfig.setCreateTime(DateUtils.getNowDate());
        return crmTelephoneConfigMapper.insertCrmTelephoneConfig(crmTelephoneConfig);
    }

    /**
     * 修改用户IP话机配置
     * 
     * @param crmTelephoneConfig 用户IP话机配置
     * @return 结果
     */
    @Override
    public int updateCrmTelephoneConfig(CrmTelephoneConfig crmTelephoneConfig)
    {
        crmTelephoneConfig.setUpdateTime(DateUtils.getNowDate());
        return crmTelephoneConfigMapper.updateCrmTelephoneConfig(crmTelephoneConfig);
    }

    /**
     * 批量删除用户IP话机配置
     * 
     * @param ids 需要删除的用户IP话机配置主键
     * @return 结果
     */
    @Override
    public int deleteCrmTelephoneConfigByIds(Long[] ids)
    {
        return crmTelephoneConfigMapper.deleteCrmTelephoneConfigByIds(ids);
    }

    /**
     * 删除用户IP话机配置信息
     * 
     * @param id 用户IP话机配置主键
     * @return 结果
     */
    @Override
    public int deleteCrmTelephoneConfigById(Long id)
    {
        return crmTelephoneConfigMapper.deleteCrmTelephoneConfigById(id);
    }

    /**
     * 根据用户ID,查询IP话机配置详细
     * @param userId
     * @return
     */
    @Override
    public CrmTelephoneConfig selectCrmTelephoneConfigByUserId(Long userId) {
        CrmTelephoneConfig crmTelephoneConfig = new CrmTelephoneConfig();
        crmTelephoneConfig.setUserId(userId);

        List<CrmTelephoneConfig> crmTelephoneConfigs = crmTelephoneConfigMapper.selectCrmTelephoneConfigList(crmTelephoneConfig);
        if (CollectionUtil.isNotEmpty(crmTelephoneConfigs)) {
            return crmTelephoneConfigs.get(0);
        }
        return null;
    }
}
